#-*- coding: UTF-8 -*-
import os
import time
import unittest
from appium import webdriver
import xlrd
import xlwt
from venv.public.readexcel import excel_action
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.touch_actions import TouchActions


desired_caps={}
desired_caps['platformName']='Android'
desired_caps['version']='7.1.1'
desired_caps['deviceName']='HGAFQ94U'#这是测试机的型号，可以查看手机的关于本机选项获得
desired_caps['unicodeKeyboard'] = 'true' # 使用unicode编码方式发送字符串
desired_caps['resetKeyboard'] = 'true'   # 隐藏键盘
# desired_caps['app'] = PATH('D:\\qq.apk')#被测试的App在电脑上的位置
desired_caps['recreateChromeDriverSessions'] = 'True'
desired_caps['appPackage'] = 'cn.com.fwd.eapp.uat'
desired_caps['appActivity'] = 'cn.com.fwd.eapp.uat.activity.SplashActivity'
driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
time.sleep(2)
#选择环境
ell = driver.find_element_by_xpath\
    ("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v7.widget.LinearLayoutCompat/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.EditText")
ell.click()
ell.send_keys("4")
#driver.hide_keyboard()
time.sleep(2)
ell2= driver.find_element_by_id("android:id/button1")
ell2.click()
#输入用户名密码
time.sleep(1)
webview = driver.contexts
view=webview[1]
driver.switch_to.context(view)
new_view = driver.current_context

driver.find_element_by_id("account").send_keys("10000796")
driver.find_element_by_id("password").send_keys("080092")
time.sleep(2)
#driver.hide_keyboard()
driver.find_element_by_xpath("//*[@id='formLogin']/button").click()
time.sleep(8)

filename ='D:/workspace/smartproject/venv/data/smartassu-chaeryn.xlsx'

excelread = xlrd.open_workbook(filename)
table = excelread.sheet_by_name('Sheet1')
h = table.nrows

def getSize():
    x = driver.get_window_size()['width']
    y = driver.get_window_size()['height']
    return (x, y)

# 屏幕向上滑动g
def swipeUp(t):
    l = getSize()
    x1 = int(l[0] * 0.5)  # x坐标
    y1 = int(l[1] * 0.75)  # 起始y坐标
    y2 = int(l[1] * 0.25)  # 终点y坐标
    driver.swipe(x1, y1, x1, y2, t)
# 屏幕向下滑动
def swipeDown(t):
    l = getSize()
    x1 = int(l[0] * 0.5)  # x坐标
    y1 = int(l[1] * 0.25)  # 起始y坐标
    y2 = int(l[1] * 0.75)  # 终点y坐标
    driver.swipe(x1, y1, x1, y2, t)
# 屏幕向左滑动
def swipLeft(t):
    l = getSize()
    x1 = int(l[0] * 0.75)
    y1 = int(l[1] * 0.5)
    x2 = int(l[0] * 0.05)
    driver.swipe(x1, y1, x2, y1, t)
# 屏幕向右滑动
def swipRight(t):
    l = getSize()
    x1 = int(l[0] * 0.05)
    y1 = int(l[1] * 0.5)
    x2 = int(l[0] * 0.75)
    driver.swipe(x1, y1, x2, y1, t)
def insuredperson():
    driver.switch_to.context("NATIVE_APP")
    time.sleep(1)
    #点击保存
    driver.tap([(1822,1159)], 500)
    #选择被保人证件号
    time.sleep(5)
    if list_login[10] == "身份证":
        driver.tap([(550, 500)], 500)
        time.sleep(5)
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        # 被保人拍照
        driver.tap([(1770, 590)], 1000)
        time.sleep(10)
        driver.tap([(1770, 590)], 1000)
        time.sleep(5)
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(5)
        #被保人证件号
        driver.find_element_by_xpath("//*[@id='insuredInfo']/div/ul[2]/li[1]/input").click()
        driver.find_element_by_xpath("//*[@id='insuredInfo']/div/ul[2]/li[1]/input").send_keys(list_login[11])
        #有效期至
        if list_login[4] == '长期':
            driver.find_element_by_xpath("//*[@id='insuredInfo']/div/ul[2]/li[2]/div[2]/label/input").click()
        else:
            js = "document.getElementById('date-yxq').removeAttribute('readonly')"
            driver.execute_script(js)
            time.sleep(2)
            driver.find_element_by_id("date-yxq").send_keys(list_login[12])
        time.sleep(1)
        driver.find_element_by_name("jobCode").send_keys(list_login[16])
        #被保人姓名
        driver.find_element_by_xpath("//*[@id='insuredInfo']/div/ul[2]/li[3]/input").send_keys(list_login[13])
        #driver.hide_keyboard()
        #职位信息
        time.sleep(2)
        driver.switch_to.context("NATIVE_APP")
        time.sleep(3)
        # 点击保存
        driver.tap([(1788, 1159)], 500)
        time.sleep(2)
    elif list_login[10] == "护照":
        driver.tap([(818, 500)], 500)
    elif list_login[10] == "出生证":
        driver.tap([(1100, 500)], 500)
    elif list_login[10] == "军官证":
        driver.tap([(1370, 500)], 500)
    elif list_login[10] == "台胞证":
        driver.tap([(531, 730)], 500)
    elif list_login[10] == "港澳回乡证":
        driver.tap([(810, 730)], 500)
    elif list_login[10] == "户口簿":
        driver.tap([(1080, 730)], 500)
def insurance():
    driver.switch_to.context("NATIVE_APP")
    time.sleep(2)
    driver.tap([(1770, 590)], 500)
    time.sleep(10)
    driver.tap([(1770, 590)], 500)
    time.sleep(5)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(1)
    #证件号
    driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[2]/li[1]/input").click()
    driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[2]/li[1]/input").send_keys(list_login[3])
    #有效期至
    if list_login[4] == '长期':
        driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[2]/li[2]/div[2]/label/input").click()
    else:
        js="document.getElementById('date-yxq').removeAttribute('readonly')"
        driver.execute_script(js)
        time.sleep(2)
        driver.find_element_by_id("date-yxq").send_keys(list_login[4])
    #出生日期
    if list_login[2] !='身份证':
        js1 = "document.getElementById('date-csrq').removeAttribute('readonly')"
        driver.execute_script(js1)
        driver.find_element_by_id("date-csrq").send_keys(list_login[6])
        time.sleep(1)
        driver.find_element_by_id("date-csrq").click()
        time.sleep(2)
        driver.switch_to.context("NATIVE_APP")
        driver.tap([(1812, 750)], 500)
        time.sleep(2)
        if list_login[7] == '男':
            driver.tap([(440, 815)], 500)
        else:
            driver.tap([(628, 815)], 500)
    else:
        pass
    #姓名
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(1)
    driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[2]/li[3]/input").send_keys(list_login[5])
    time.sleep(1)
    #职位信息
    driver.find_element_by_name("jobCode").send_keys(list_login[8])
    time.sleep(5)
    if list_login[9] == "本人":
        time.sleep(2)
        driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[3]/li[3]/div/label[1]").click()
    elif list_login[9] == "父母":
        driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[3]/li[3]/div/label[2]").click()
        insuredperson()
    elif list_login[9] == "配偶":
        driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[3]/li[3]/div/label[3]").click()
        insuredperson()
    elif list_login[9] == "子女":
        driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[3]/li[3]/div/label[4]").click()
        insuredperson()
    elif list_login[9] == "其他":
        driver.find_element_by_xpath("//*[@id='applicantInfo']/div/ul[3]/li[3]/div/label[1]").click()
    driver.switch_to.context("NATIVE_APP")
    #点击保存
    time.sleep(2)
    driver.tap([(1727, 1152)], 500)
    time.sleep(10)
#创建存保单号的excel
workbook = xlwt.Workbook()
sheet1 =workbook.add_sheet("issid")
row1=1
#获取当前时间
localtime = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))

for i in range(2,h):
    excel = excel_action()
    list_login = excel.read_excel_row(filename, 0, i)  # read excel data
    print(list_login)
    driver.switch_to.context("NATIVE_APP")
    time.sleep(8)
    # 点击在线投保
    driver.tap([(850, 700)], 500)
    time.sleep(10)

    if list_login[0] == "生命保障":
        driver.tap([(128, 602)], 500)
        time.sleep(2)
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(2)
        i = 2
        j = 0
        while i<8:
            title = driver.find_elements_by_class_name("title")[i].text
            tagtop = driver.find_elements_by_class_name("tag-top-right")[j].text
            title2 = title + tagtop
            if title2 == list_login[1]:
                print(title2)
                driver.find_elements_by_class_name("title")[i].click()
                break
            else:
                i = i + 1
                j = j + 1
        time.sleep(3)
    elif list_login[0] == '意外':
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        a1 = driver.find_element_by_xpath("//*[@id='selectProduct']/ul/li[2]")
        TouchActions(driver).tap(a1).perform()
        time.sleep(4)
        driver.find_element_by_xpath("//*[text()='%s']" % list_login[1]).click()
    elif list_login[0] == '重疾':
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        a2 = driver.find_element_by_xpath("//*[@id='selectProduct']/ul/li[3]")
        TouchActions(driver).tap(a2).perform()
        time.sleep(4)
        driver.find_element_by_xpath("//*[text()='%s']" % list_login[1]).click()
    elif list_login[0] == '理财':
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        a3 = driver.find_element_by_xpath("//*[@id='selectProduct']/ul/li[4]")
        TouchActions(driver).tap(a3).perform()
        time.sleep(4)
        titlename = 2
        tagname = 0
        while titlename < 8:
            titlename1 = driver.find_elements_by_class_name("title")[titlename].text
            tagname1 = driver.find_elements_by_class_name("tag-top-right")[tagname].text
            title3 = titlename1 + tagname1
            if title3 == list_login[1]:
                print(title3)
                driver.find_elements_by_class_name("title")[titlename].click()
                break
            else:
                titlename = titlename + 1
                tagname = tagname + 1
        time.sleep(3)

    if list_login[2] == "身份证":
        #点击身份证
        time.sleep(4)
        a4 = driver.find_element_by_xpath("//*[@id='applicantInfo']/section/div/ul/li[1]")
        time.sleep(1)
        TouchActions(driver).tap(a4).perform()
        time.sleep(2)
        insurance()
    elif list_login[2] == "护照":
        driver.tap([(943, 520)], 500)
    elif list_login[2] == "军官证":
        driver.tap([(1206, 520)], 500)
    elif list_login[2] == "台胞证":
        time.sleep(4)
        a5 = driver.find_element_by_xpath("//*[@id='applicantInfo']/section/div/ul/li[4]/label")
        TouchActions(driver).tap(a5).perform()
        time.sleep(2)
        insurance()
    elif list_login[2] == "港澳回乡证":
        driver.tap([(960, 730)], 500)
    #投保信息
    time.sleep(6)
    #点击修改保额
    time.sleep(3)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(3)
    driver.find_element_by_xpath("//*[@id='productPremium']/section/section[3]/div[2]/section/div/div[2]/div/div[1]").click()
    time.sleep(5)
    driver.find_element_by_name('num').clear()
    time.sleep(5)
    driver.find_element_by_name('num').send_keys(list_login[21])
    #driver.hide_keyboard()
    time.sleep(1)
    driver.switch_to.context("NATIVE_APP")
    time.sleep(2)
    driver.tap([(1605, 709)], 500)
    time.sleep(1)
    #添加附加险
    time.sleep(1)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(1)
    if list_login[22] == "有":
        driver.find_element_by_xpath("//*[@id='productPremium']/section/section[3]/div[2]/section/div/div[2]/div/div[2]/i").click()
        time.sleep(1)
        driver.switch_to.context("NATIVE_APP")
        print(driver.current_context)
        time.sleep(3)
        driver.tap([(398, 317)], 500)
        #点击确认
        time.sleep(1)
        driver.tap([(1600, 1132)], 500)
        time.sleep(8)
        #计算保费
        driver.tap([(1700, 1160)], 500)
        time.sleep(10)
        driver.tap([(1700, 1160)], 500)
        time.sleep(7)
    else:
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        #点击计算保费
        driver.tap([(1700, 1160)], 500)
        time.sleep(10)
        driver.tap([(1700, 1160)], 500)
        time.sleep(7)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(5)
    driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[1]/div[1]/p").click()
    time.sleep(2)
    driver.switch_to.context("NATIVE_APP")
    time.sleep(2)
    #投保人信息
    driver.tap([(470, 430)], 500)
    time.sleep(1)
    #婚姻状况
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    if list_login[23] == "未婚":
        driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/section/ul[1]/li[1]/div/label[1]").click()
    else:
        driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/section/ul[1]/li[1]/div/label[2]").click()
    time.sleep(1)
    driver.find_element_by_name("education").click()
    time.sleep(2)
    if list_login[24] == "博士":
        Select(driver.find_element_by_name("education")).select_by_value("11")
    elif list_login[24] == "硕士":
        Select(driver.find_element_by_name("education")).select_by_value("14")
    elif list_login[24] == "本科":
        Select(driver.find_element_by_name("education")).select_by_value("21")
    elif list_login[24] == "大专":
        Select(driver.find_element_by_name("education")).select_by_value("31")
    elif list_login[24] == "中专":
        Select(driver.find_element_by_name("education")).select_by_index("41")
    elif list_login[24] == "中技":
        Select(driver.find_element_by_name("education")).select_by_value("47")
    elif list_login[24] == "高中":
        Select(driver.find_element_by_name("education")).select_by_value("61")
    elif list_login[24] == "初中":
        Select(driver.find_element_by_name("education")).select_by_value("71")
    elif list_login[24] == "小学":
        Select(driver.find_element_by_name("education")).select_by_value("81")
    elif list_login[24] == "其他":
        Select(driver.find_element_by_name("education")).select_by_value("90")
    driver.find_element_by_name("nationality").click()
    time.sleep(1)
    if list_login[25] == '中国':
        Select(driver.find_element_by_name("nationality")).select_by_value("CHN")
    elif list_login[25] == '中国香港':
        Select(driver.find_element_by_name("nationality")).select_by_value("HKG")
    elif list_login[25] == '中国澳门':
        Select(driver.find_element_by_name("nationality")).select_by_value("MAC")
    elif list_login[25] == '中国台湾':
        Select(driver.find_element_by_name("nationality")).select_by_value("TWN")
    #个人年收入
    driver.find_element_by_name("personalIncome").send_keys(list_login[26])
    #家庭年收入
    driver.find_element_by_name("familyIncome").send_keys(list_login[27])
    time.sleep(1)
    #817 760
    #家庭地址
    driver.switch_to.context("NATIVE_APP")
    driver.tap([(761, 913)], 500)
    time.sleep(1)
    driver.swipe(357, 1000, 357, 200, 3500)
    time.sleep(1)
    driver.swipe(357, 1000, 357, 660, 3500)
    if list_login[28] == '广东省广州市天河区':
        driver.swipe(1633, 993, 1633, 800, 3500)
    elif list_login[28] == "广东省广州市海珠区":
        driver.swipe(1633, 993, 1633, 867, 3500)
    elif list_login[28] == "广东省广州市越秀区":
        driver.swipe(1633, 993, 1633, 936, 3500)
    time.sleep(2)
    driver.tap([(1820, 737)], 500)
    time.sleep(1)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(1)
    driver.find_element_by_name("familyAddrDetail").send_keys(list_login[29])
    #家庭邮编
    driver.find_element_by_name("familyPostcode").send_keys(list_login[30])
    #单位名称
    driver.find_element_by_name("unitName").send_keys(list_login[31])
    #单位地址
    driver.switch_to.context("NATIVE_APP")
    time.sleep(2)
    driver.tap([(747, 730)], 500)
    time.sleep(2)
    driver.swipe(357, 1000, 357, 200, 3500)
    time.sleep(1)
    driver.swipe(357, 1000, 357, 660, 3500)
    if list_login[32] == '广东省广州市天河区':
        driver.swipe(1633, 993, 1633, 800, 3500)
    elif list_login[32] == "广东省广州市海珠区":
        driver.swipe(1633, 993, 1633, 867, 3500)
    elif list_login[32] == "广东省广州市越秀区":
        driver.swipe(1633, 993, 1633, 936, 3500)
    time.sleep(2)
    driver.tap([(1820, 737)], 500)
    #单位详细地址
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(1)
    driver.find_element_by_name("workAddrDetail").send_keys(list_login[33])
    #单位邮编
    driver.find_element_by_name("workPostcode").send_keys(list_login[34])
    #邮箱
    driver.find_element_by_name("email").send_keys(list_login[35])
    time.sleep(2)
    # action = TouchAction(driver)
    driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/div[2]/button[2]").click()
    driver.switch_to.context("NATIVE_APP")
    #点击确认
    driver.tap([(1286, 1038)], 500)
    time.sleep(5)
    if list_login[13] != "":
        time.sleep(3)
        swipeDown(1000)
        swipeDown(1000)
        time.sleep(2)
        #点击被保人
        driver.tap([(770, 412)], 500)
        TouchAction(driver).long_press(x=770,y=412).perform()
        time.sleep(1)
        # 被保人婚姻状况
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(2)
        if list_login[36] == "未婚":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/section/ul[1]/li[1]/div/label[1]").click()
        else:
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/section/ul[1]/li[1]/div/label[2]").click()
        time.sleep(1)
        driver.find_element_by_name("education").click()
        time.sleep(2)
        if list_login[37] == "博士":
            Select(driver.find_element_by_name("education")).select_by_value("11")
        elif list_login[37] == "硕士":
            Select(driver.find_element_by_name("education")).select_by_value("14")
        elif list_login[37] == "本科":
            Select(driver.find_element_by_name("education")).select_by_value("21")
        elif list_login[37] == "大专":
            Select(driver.find_element_by_name("education")).select_by_value("31")
        elif list_login[37] == "中专":
            Select(driver.find_element_by_name("education")).select_by_index("41")
        elif list_login[37] == "中技":
            Select(driver.find_element_by_name("education")).select_by_value("47")
        elif list_login[37] == "高中":
            Select(driver.find_element_by_name("education")).select_by_value("61")
        elif list_login[37] == "初中":
            Select(driver.find_element_by_name("education")).select_by_value("71")
        elif list_login[37] == "小学":
            Select(driver.find_element_by_name("education")).select_by_value("81")
        elif list_login[37] == "其他":
            Select(driver.find_element_by_name("education")).select_by_value("90")
        driver.find_element_by_name("nationality").click()
        time.sleep(1)
        if list_login[38] == '中国':
            Select(driver.find_element_by_name("nationality")).select_by_value("CHN")
        elif list_login[38] == '中国香港':
            Select(driver.find_element_by_name("nationality")).select_by_value("HKG")
        elif list_login[38] == '中国澳门':
            Select(driver.find_element_by_name("nationality")).select_by_value("MAC")
        elif list_login[38] == '中国台湾':
            Select(driver.find_element_by_name("nationality")).select_by_value("TWN")
        #被保人年收入
        driver.find_element_by_name("personalIncome").send_keys(list_login[62])
        # 家庭地址
        time.sleep(1)
        a6=driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/section/ul[2]/li[1]/div/input[4]")
        TouchActions(driver).tap(a6).perform()
        time.sleep(2)
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.swipe(357, 1000, 357, 200, 3500)
        time.sleep(1)
        driver.swipe(357, 1000, 357, 660, 3500)
        time.sleep(1)
        if list_login[39] == '广东省广州市天河区':
            driver.swipe(1633, 993, 1633, 800, 3500)
        elif list_login[39] == "广东省广州市海珠区":
            driver.swipe(1633, 993, 1633, 867, 3500)
        elif list_login[39] == "广东省广州市越秀区":
            driver.swipe(1633, 993, 1633, 936, 3500)
            print("走这里了吗")
        time.sleep(2)
        driver.tap([(1820, 737)], 500)
        time.sleep(1)
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(1)
        driver.find_element_by_name("familyAddrDetail").send_keys(list_login[40])
        # 家庭邮编
        driver.find_element_by_name("familyPostcode").send_keys(list_login[41])
        # 单位名称
        driver.find_element_by_name("unitName").send_keys(list_login[42])
        # 邮箱
        driver.find_element_by_name("email").send_keys(list_login[46])
        # 单位地址
        a7=driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/section/ul[3]/li[2]/div/input[4]")
        TouchActions(driver).tap(a7).perform()
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.swipe(357, 1000, 357, 200, 3500)
        time.sleep(1)
        driver.swipe(357, 1000, 357, 660, 3500)
        driver.switch_to.context("NATIVE_APP")
        if list_login[43] == '广东省广州市天河区':
            driver.swipe(1633, 993, 1633, 800, 3500)
        elif list_login[43] == "广东省广州市海珠区":
            driver.swipe(1633, 993, 1633, 867, 3500)
        elif list_login[43] == "广东省广州市越秀区":
            driver.swipe(1633, 993, 1633, 936, 3500)
        time.sleep(2)
        driver.tap([(1820, 737)], 500)
        # 单位详细地址
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(1)
        driver.find_element_by_name("workAddrDetail").send_keys(list_login[44])
        # 单位邮编
        driver.find_element_by_name("workPostcode").send_keys(list_login[45])
        time.sleep(2)
        # action = TouchAction(driver)
        driver.find_element_by_xpath(
            "//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/div[2]/button[2]").click()

        # 点击确认
        a8 =driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/div[2]/button[2]")
        TouchActions(driver).tap(a8).perform()
        driver.switch_to.context("NATIVE_APP")
        time.sleep(8)
        swipeDown(1000)
        swipeDown(1000)
        time.sleep(1)
        #受益人
        time.sleep(2)
        driver.tap([(1100, 419)], 500)
        time.sleep(5)
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(2)
        a9= driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/seaction/div[1]/label[1]")
        TouchActions(driver).tap(a9).perform()
        time.sleep(2)
        a10 =driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[1]/div[2]/div/div/button")
        TouchActions(driver).tap(a10).perform()
    else:
        swipeDown(1000)
        swipeDown(1000)
        time.sleep(2)
        driver.tap([(789, 429)], 500)
        time.sleep(2)
        driver.tap([(505, 582)], 500)
        time.sleep(2)
        driver.tap([(1093, 715)], 500)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    #输入投保人手机号及验证码
    driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[2]/div[1]/div/input").send_keys(list_login[48])
    driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[2]/div[1]/div/p/span").click()
    driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[2]/div[1]/div/p/input").send_keys("999999")
    time.sleep(2)
    #输入被保人手机号及验证码
    if list_login[49] != '':
        driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[2]/div[2]/div/input").send_keys(list_login[49])
        driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[2]/div[2]/div/p/span").click()
        driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[2]/div[2]/div/p/input").send_keys("999999")
    else:
        print("无被保人")
    driver.switch_to.context("NATIVE_APP")
    time.sleep(1)
    swipeUp(1000)
    time.sleep(1)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    try:
        inns = driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[1]/div/select")
        inns.click()
        if list_login[50] == "自动垫付":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[1]/div/select/option[2]").click()
        else:
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[1]/div/select/option[3]").click()
    except Exception:
        pass
        #raise Exception("Element not found.")
    #现金红利处理方式
    try:
        cash =driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[2]/div/select")
        cash.click()
        time.sleep(1)
        if list_login[51] == "累计生息":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[2]/div/select/option[2]").click()
        elif list_login[51] == "现金领取":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[2]/div/select/option[3]").click()
        elif list_login[51] == "抵缴保费":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[2]/div/select/option[4]").click()
    except Exception:
        pass
        #raise Exception("Element not found.")

    # 年金处理方式
    try:
        annuity = driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[3]/div/select")
        annuity.click()
        time.sleep(1)
        if list_login[52] == "累计生息":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[3]/div/select/option[2]").click()
        elif list_login[52] == "现金领取":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[3]/div/select/option[3]").click()
        elif list_login[52] == "抵缴保费":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[3]/div/select/option[4]").click()
    except Exception:
        #raise Exception("Element not found.")
        pass
    # 生存金处理方式
    try:
        survival =driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[4]/div/select")
        survival.click()
        time.sleep(1)
        if list_login[53] == "累计生息":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[4]/div/select/option[2]").click()
        elif list_login[53] == "现金领取":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[4]/div/select/option[3]").click()
        elif list_login[53] == "抵缴保费":
            driver.find_element_by_xpath(
                "//*[@id='addInformation']/section/div[2]/div[3]/div[1]/div[4]/div/select/option[4]").click()
    except Exception:
        pass
        #raise Exception("Element not found.")

    #保单通讯地址
    time.sleep(1)
    driver.switch_to.context("NATIVE_APP")
    time.sleep(1)
    #点一下其他地方
    driver.tap([(1195, 603)], 500)
    time.sleep(1)
    #点击地址+号
    # driver.tap([(672,936)],500)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    addre=driver.find_element_by_xpath("//div[@class='add-address-wrap']/div[1]/p[1]/i")
    TouchActions(driver).tap(addre).perform()
    time.sleep(7)
    #swipeUp(1000)
    driver.find_element_by_xpath("//*[@id='addInformation']/section/div[2]/div[3]/div[2]/div[1]/div/div[2]/div[1]/div[1]").click()
    time.sleep(2)
    #告知问卷
    time.sleep(1)
    driver.switch_to.context("NATIVE_APP")
    swipeUp(1000)
    time.sleep(1)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    try:
        tips = driver.find_element_by_xpath("//*[text()='人身投保提示书-营销员渠道']")
    except NoSuchElementException:
        print("无人身投保提示书告知")
    else:
        time.sleep(3)
        TouchActions(driver).tap(tips).perform()
        time.sleep(7)
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[2]/p/label/input").click()
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.tap([(1723, 1143)], 500)
        time.sleep(5)
        driver.tap([(1723, 1143)], 500)
        time.sleep(5)
    try:
        time.sleep(1)
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(2)
        shuishou = driver.find_element_by_xpath("//*[text()='个人税收居民身份声明']")
    except NoSuchElementException:
        print("无个人税收居民身份声明")
    else:
        TouchActions(driver).tap(shuishou).perform()
        time.sleep(2)
        driver.find_element_by_name("N1140001").click()
        time.sleep(1)
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div/div/select/option[2]").click()
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.tap([(1723, 1143)], 500)
        time.sleep(5)
        driver.tap([(1723, 1143)], 500)
        time.sleep(5)
    #基本告知sio
    try:
        time.sleep(3)
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        kown = driver.find_element_by_xpath("//*[text()='基本告知(SIO)']")
    except NoSuchElementException:
        print("没有基本告知（SIO）")
    else:
        TouchActions(driver).tap(kown).perform()
        time.sleep(5)
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[1]/div/label[2]/input").click()
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[2]/div/label[2]/input").click()
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[3]/div/label[2]/input").click()
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[4]/div/label[2]/input").click()
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[5]/div/label[2]/input").click()
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[6]/div/label[2]/input").click()
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[7]/div/label[2]/input").click()
        driver.find_element_by_xpath("//*[@id='getQuestionData']/div/div[8]/div/label[2]/input").click()
        time.sleep(1)
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.tap([(1723, 1143)], 500)
        time.sleep(5)
        driver.tap([(1723, 1143)], 500)
        time.sleep(10)
    #基本告知
    try:
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(1)
        basickown = driver.find_element_by_xpath("//*[text()='基本告知']")
    except NoSuchElementException:
        print("没有基本告知")
    else:
        time.sleep(1)
        TouchActions(driver).tap(basickown).perform()
        time.sleep(5)
        #  除本公司产品外，是否已购买或正在申请其它保险公司的人身保险合同？
        driver.find_elements_by_name("N0010001")[1].click()
        #  您是否拥有公费医疗、社会医疗保险、其它商业保险公司提供的费用补偿型医疗保险或本公司认可的费用补偿型医疗保险？
        driver.find_elements_by_name("N0010007")[1].click()
        #  您是否正在或试图参加私人性质飞行，或携带氧气瓶潜水、或登山、或从事危险性的运动？
        driver.find_elements_by_name("N0010008")[1].click()
        #  PA单：您是否正计划前往其它国家或海外地区旅行、工作或居住？
        driver.find_elements_by_name("N0010009")[1].click()
        if list_login[15] == '女':
        #  您目前是否怀孕？
            driver.find_elements_by_name("N0050001")[1].click()
        # 是否曾患有或被告知患有任何子宫、宫颈、输卵管、阴道、卵巢或乳房之疾病或失调，或因怀孕而导致并发症，如高血压、糖尿病等；
            driver.find_elements_by_name("N0050003")[1].click()
        elif list_login[7] == '女' and list_login[9] == '本人':
            driver.find_elements_by_name("N0050001")[1].click()
            driver.find_elements_by_name("N0050003")[1].click()
        else:
            pass
        #身高
        driver.find_element_by_name("N0030001").send_keys("165")
        #体重
        driver.find_element_by_name("N0030002").send_keys("55")
        # 过去一年内是否有体重增/减大于 5 公斤
        driver.find_elements_by_name("N0030003")[1].click()
        # A、接受或被建议接受以下检查，且检查结果有异常；
        driver.find_elements_by_name("N003002001")[1].click()
        # B、接受输血或捐血而不被接受；
        driver.find_elements_by_name("N003002002")[1].click()
        # C、接受或被建议接受检查诊疗、手术、住院治疗；
        driver.find_elements_by_name("N003002003")[1].click()
        # D、接受任何药物治疗或医疗护理；
        driver.find_elements_by_name("N003002004")[1].click()
        #   11.  您是否有身体残障情况：
        driver.find_elements_by_name("N003003001")[1].click()
        driver.find_elements_by_name("N003003002")[1].click()
        driver.find_elements_by_name("N003003003")[1].click()
        #   12.  A、与心脑等循环系統疾病有关的疾病，如风湿性心脏病、高血压、心肌梗塞、脑血管意外（中风或出血等）、先天性或缺血性心脏病；
        driver.find_elements_by_name("N003004001")[1].click()
        # 13.  B、血液有关的疾病如血友病、贫血、白血病、紫癲等疾病；
        driver.find_elements_by_name("N003004002")[1].click()
        #14.   C、五官有关的疾病，如高度近视、青光眼、白内障、失明、视网膜出血或剥离、眼底病变、耳鼻喉或口腔疾病等
        driver.find_elements_by_name("N003004003")[1].click()
        # 15.  D、消化系統有关的疾病，如消化道溃疡或出血穿孔、肛管疾病、疝气、胰腺炎、肝病； （若为乙型肝炎，请注明）；
        driver.find_elements_by_name("N003004004")[1].click()
        # 16.  E、泌尿系统有关的疾病，如膀胱疾病、肾病、肾结石、肾炎等；
        driver.find_elements_by_name("N003004005")[1].click()
        # 17.  F、呼吸系統疾病如哮喘、支气管炎、肺气肿、肺扩张或肺結核；
        driver.find_elements_by_name("N003004006")[1].click()
        # 18.  G、肌肉或骨骼有关的毛病，如各类关节炎、瘫瘓、痛风、脊椎疾病、畸形、肢体被切除或严重受伤；
        driver.find_elements_by_name("N003004007")[1].click()
        # 19.  H、神经系统及免疫系统疾病，如精神病、震颤、眩晕、酒精或药物滥用成瘾、癫痫、智障、帕金森综合征或精神不正常，系统性红斑狼疮、多发性硬化症、硬皮病等；
        driver.find_elements_by_name("N003004008")[1].click()
        # 20.  I、癌症、肿瘤、息肉、囊肿、任何透过性接触传染的疾病、HIV 感染、后天免疫能力缺乏症（艾滋病）或艾滋病并发症；
        driver.find_elements_by_name("N003004009")[1].click()
        # 21.  J、糖尿病、痛风、甲状腺疾病（如甲状腺结节、甲状腺功能亢进或减退）
        driver.find_elements_by_name("N003004010")[1].click()
        # 22.  K、是否还有其他以上未提及的疾病及症状，而需要接受检查、治疗或住院？
        driver.find_elements_by_name("N003004011")[1].click()
        # 23.  您的配偶是否曾接受或试图接受与艾滋病（AIDS）有关的医疗咨询、检查或治疗；
        driver.find_elements_by_name("N0030075")[1].click()
        # 24.  是否曾在过去 6 个月内持续一周以上有下列症状：
        driver.find_elements_by_name("N0030076")[1].click()
        # 25.  您的家属（父母、兄弟姐妹）是否曾患有或正患有以下疾病（高血压、肾病、心脏病、
        # 肝肾囊肿、肝硬化、糖尿病、精神病、白血病、结核病、多发性硬化症、癌症或其它急慢性重大疾病）
        driver.find_elements_by_name("N0030080")[1].click()
        # 26.  您是否吸烟或曾吸烟
        driver.find_elements_by_name("N0040001")[1].click()
        # 27.  您是否有或曾有饮酒的习惯？
        driver.find_elements_by_name("N0040005")[1].click()
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.tap([(1723, 1143)], 500)
        time.sleep(8)
        driver.tap([(1723, 1143)], 500)
        time.sleep(15)
    try:
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(2)
        basickownGIO = driver.find_element_by_xpath("//*[text()='基本告知(GIO)']")
    except NoSuchElementException:
        print("没有基本告知GIO")
        time.sleep(3)
    else:
        TouchActions(driver).tap(basickownGIO).perform()
        time.sleep(8)
        driver.find_elements_by_name("N0100001")[1].click()
        driver.find_elements_by_name("N0100002")[1].click()
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.tap([(1723, 1143)], 500)
        time.sleep(5)
        driver.tap([(1723, 1143)], 500)
        time.sleep(10)
    #点击下一步
    time.sleep(1)
    driver.switch_to.context("NATIVE_APP")
    time.sleep(8)
    driver.tap([(1723, 1143)], 500)
    time.sleep(12)
    #缴费方式
    time.sleep(1)
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    a11=driver.find_element_by_xpath("//*[@id='payment']/div[1]/div[2]/div[1]/div/div")
    TouchActions(driver).tap(a11).perform()
    time.sleep(1)
    #账户持有人
    driver.find_element_by_xpath("//*[@id='payment']/div[1]/div[2]/div[2]/div[1]/section/ul/ul/li[1]/div/select").click()
    driver.find_element_by_xpath("//*[@id='payment']/div[1]/div[2]/div[2]/div[1]/section/ul/ul/li[1]/div/select/option[2]").click()
    #银行名称
    driver.find_element_by_name("bankCode").click()
    if list_login[55] == "中国银行":
        Select(driver.find_element_by_name("bankCode")).select_by_value("104")
    elif list_login[55] == "中国工商银行":
        Select(driver.find_element_by_name("bankCode")).select_by_value("102")
    elif list_login[55] == "中国建设银行":
        Select(driver.find_element_by_name("bankCode")).select_by_value("105")
    elif list_login[55] == "招商银行":
        Select(driver.find_element_by_name("bankCode")).select_by_value("308")
    elif list_login[55] == "交通银行":
        Select(driver.find_element_by_name("bankCode")).select_by_value("301")
    elif list_login[55] == "中国农业银行":
        Select(driver.find_element_by_name("bankCode")).select_by_value("103")
    #银行卡类型
    driver.find_element_by_name("bankTypeCode").click()
    if list_login[56] == "储蓄卡":
        Select(driver.find_element_by_name("bankTypeCode")).select_by_value("0")
    else:
        Select(driver.find_element_by_name("bankTypeCode")).select_by_value("1")
    #银行卡号
    driver.find_element_by_name("bankNo").send_keys(list_login[57])
    time.sleep(1)
    #确认按钮
    driver.find_element_by_xpath("//*[@id='payment']/div[1]/div[2]/div[2]/div[2]/button[2]").click()
    time.sleep(4)
    driver.find_element_by_css_selector(".bank-info.bank-104").click()
    # #选择银行
    # driver.find_element_by_xpath("//*[@id='payment']/div[1]/div[2]/div[2]/div[1]/div/div/div/div").click()
    # driver.switch_to.context("NATIVE_APP")
    driver.switch_to.context("NATIVE_APP")
    time.sleep(1)
    swipeUp(1000)
    #判断是否有续期缴费
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    try:
        a14 = driver.find_element_by_xpath("//*[text()='请选择续期缴费']")
    except NoSuchElementException:
        print("无续期缴费")
    else:
        time.sleep(2)
        driver.find_elements_by_css_selector(".icon-add-box.icon-add")[1].click()
        time.sleep(4)
        driver.find_elements_by_css_selector(".bank-info.bank-104")[1].click()

    #判断是否有收款账户
    try:
        payment= driver.find_element_by_xpath("//*[text()='请选择收益收款账户']")
        payment1 = driver.find_element_by_xpath("//*[text()='投保人']")
    except NoSuchElementException:
        print('no cancelBtn')   #当没有这个元素就打印出no cancelBtn
    else:
        time.sleep(4)
        driver.find_elements_by_css_selector(".icon-add-box.icon-add")[2].click()
        time.sleep(4)
        driver.find_elements_by_css_selector(".bank-info.bank-104")[2].click()
    time.sleep(1)
    #判断是否有被保人收款账号
    try:
        payment2 = driver.find_element_by_xpath("//*[text()='被保人']")
    except NoSuchElementException:
        print('no cancelBtn')  # 当没有这个元素就打印出no cancelBtn
    else:
        time.sleep(2)
        driver.find_elements_by_css_selector(".icon-add-box.icon-add")[3].click()
        # 账户持有人
        driver.find_element_by_xpath(
            "//*[@id='payment']/div[1]/div[5]/div[2]/div[2]/div[1]/section/ul/ul/li[1]/div/select").click()
        driver.find_element_by_xpath(
            "//*[@id='payment']/div[1]/div[5]/div[2]/div[2]/div[1]/section/ul/ul/li[1]/div/select/option[3]").click()
        # 银行名称
        driver.find_element_by_name("bankCode").click()
        if list_login[59] == "中国银行":
            Select(driver.find_element_by_name("bankCode")).select_by_value("104")
        elif list_login[59] == "中国工商银行":
            Select(driver.find_element_by_name("bankCode")).select_by_value("102")
        elif list_login[59] == "中国建设银行":
            Select(driver.find_element_by_name("bankCode")).select_by_value("105")
        elif list_login[59] == "招商银行":
            Select(driver.find_element_by_name("bankCode")).select_by_value("308")
        elif list_login[59] == "交通银行":
            Select(driver.find_element_by_name("bankCode")).select_by_value("301")
        elif list_login[59] == "中国农业银行":
            Select(driver.find_element_by_name("bankCode")).select_by_value("103")
        # 银行卡类型
        driver.find_element_by_name("bankTypeCode").click()
        if list_login[60] == "储蓄卡":
            Select(driver.find_element_by_name("bankTypeCode")).select_by_value("0")
        else:
            Select(driver.find_element_by_name("bankTypeCode")).select_by_value("1")
        # 银行卡号
        driver.find_element_by_name("bankNo").send_keys(list_login[61])
        time.sleep(1)
        #点击确认
        driver.find_element_by_xpath("//*[@id='payment']/div[1]/div[5]/div[2]/div[2]/div[2]/button[2]").click()
        time.sleep(1)
        time.sleep(4)
        driver.find_elements_by_css_selector(".bank-info.bank-105")[0].click()
    driver.switch_to.context("NATIVE_APP")
    time.sleep(5)
    driver.tap([(1686, 1149)], 500)
    time.sleep(15)
    driver.tap([(1686, 1149)], 500)
    time.sleep(15)

    #获取保单号
    driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
    time.sleep(2)
    assid = driver.find_element_by_xpath("//*[@id='pageMain']/div[2]/div/div[1]/em")
    assidtext =assid.text
    print(assidtext)
    sheet1.write(row1,0,list_login[3])
    sheet1.write(row1,1,list_login[5])
    sheet1.write(row1,2,assidtext)
    workbook.save("D:\\workspace\\smartproject\\venv\\Result\\"+localtime+".xls")
    row1= row1+1
    #如有被保人签名
    driver.switch_to.context("NATIVE_APP")
    time.sleep(3)
    driver.tap([(917, 534)], 500)
    time.sleep(1)
    driver.swipe(574,516,1019,690,3000)
    time.sleep(1)
    driver.tap([(1436, 1138)], 500)
    time.sleep(3)
    #代理人签名
    try:
        driver.switch_to.context("WEBVIEW_cn.com.fwd.eapp.uat")
        time.sleep(1)
        dailiren = driver.find_element_by_xpath("//*[@id='pageMain']/div[2]/div/ul/li[3]/p")
    except NoSuchElementException:
        print('no cancelBtn')  # 当没有这个元素就打印出no cancelBtn
    else:
        driver.switch_to.context("NATIVE_APP")
        time.sleep(1)
        driver.tap([(1534, 533)], 500)
        time.sleep(1)
        driver.swipe(574, 516, 1019, 690, 3000)
        time.sleep(1)
        driver.tap([(1436, 1138)], 500)

    #投保人签名
    driver.switch_to.context("NATIVE_APP")
    time.sleep(3)
    driver.tap([(321, 548)],500)
    time.sleep(2)
    driver.swipe(574,516,1019,690,3000)
    time.sleep(1)
    driver.tap([(1436, 1138)], 500)
    #点击支付
    time.sleep(10)
    driver.tap([(1718, 1145)], 500)
    time.sleep(15)
    #点击到投保选择页面
    time.sleep(5)
    driver.tap([(114, 61)], 500)
    time.sleep(6)